package com.novelastudios.application
{
	/**
	 * Intended to be a quick access to version and application name and only these two things.
	 * 
	 * @example Place this on the root of your application
	 * 	<listing version="3.0">
	 * 		ApplicationInformation.version = "1.0.0.0";
	 * 		ApplicationInfromation.name    = "My App";
	 * 		trace(ApplicationInformation.isBeta);
	 * 	</listing>
	 *  
	 * @author JohnBailey
	 * 
	 */	
	public class ApplicationInformation
	{		
		internal static var _instance:Instance;
		
		public static var DEBUGGING:Boolean = false; 
		
		public static function get instance():Instance
		{
			return (_instance == null) ? (_instance = new Instance()) : _instance;
		}
		
		
		
		
		////////////////////////////////////////////////
		//---------------------
		// name
		//---------------------
		/**
		 * Can only be set once
		 */ 
		public static function set name(value:String):void
		{
			instance.name = value;
		}
		public static function get name():String
		{
			return instance.name;
		}
		/**
		 * Determine if the name has been set 
		 * 
		 * @return 
		 * 
		 */		
		public static function get isUsingDefaultName():Boolean
		{
			return (instance.name==Instance.DEFAULT_NAME);
		}
		
		////////////////////////////////////////////////
		//---------------------
		// version
		//---------------------
		/**
		 * Can only be set once
		 */ 
		public static function set version(value:String):void
		{
			instance.version = value;
		}
		public static function get version():String
		{
			return instance.version;
		}
		public static function get isUsingDefaultVersion():Boolean
		{
			return (instance.name==Instance.DEFAULT_VERSION);
		}
		
		////////////////////////////////////////////////
		//---------------------
		// isAlpha (read-only)
		//---------------------
		public static function get isAlpha():Boolean
		{
			return instance.isAlpha;
		}
		
		////////////////////////////////////////////////
		//---------------------
		// isBeta (read-only)
		//---------------------
		public static function get isBeta():Boolean
		{
			return instance.isBeta;
		}
		
		////////////////////////////////////////////////
		//---------------------
		// isFinal (read-only)
		//---------------------
		public static function get isFinal():Boolean
		{
			return instance.isFinal;
		}
	}
}

internal class Instance
{
	internal static const DEFAULT_NAME:String 	 = "unnamed application";
	internal static const DEFAULT_VERSION:String = "0.0.0.0"; 
	internal var _name:String 	= DEFAULT_NAME;
	internal var _version:String = DEFAULT_VERSION;
	
	/**
	 * @private
	 */
	internal var _isBeta:Boolean;
	
	/**
	 * @private
	 */
	internal var _isAlpha:Boolean;
	
	public function get name():String
	{
		return _name;
	}
	
	public function get version():String
	{
		return _version;
	}
	
	public function get isFinal():Boolean
	{
		return (!_isBeta && _isAlpha);
	}
	
	public function get isBeta():Boolean
	{
		return _isBeta;
	}
	
	public function get isAlpha():Boolean
	{
		return _isAlpha;
	}
	
	/**
	 * Can only be set once
	 */ 
	public function set name(value:String):void
	{
		if(_name != DEFAULT_NAME) return;
		_name = value;
	}
	
	/**
	 * Can only be set once
	 */ 
	public function set version(value:String):void
	{
		if(_version != DEFAULT_VERSION) return;
		
		_version = value;
		
		_isBeta  = (_version.indexOf("_") > -1 || _version.indexOf("b") > -1);
		
		_isAlpha  = _version.indexOf("a") > -1;
	}
}